package com.example.demo.dao;


import java.util.List;
import java.util.Set;

import com.example.demo.entity.User;
import com.example.demo.entity.UserAndRole;
import com.example.demo.mapper.UserMapper;

/**
 * 用户数据查询类
 * @author Henry.Y
 * @data 2019年5月23日
 */
public class UserDao extends BaseDao implements UserMapper{

	public int createUser(String sqlId,User user){
		
		return operateInsertSql(sqlId,user);
	}
	
	public int deleteUser(String sqlId,String id){
		
		return operateDeleteSql(sqlId,id);
	}
	
	public void updatePassword(String sqlId,User user){
		
		operateUpdateSql(sqlId,user);
	}
	
	public int correlateRoles(String sqlId,List<UserAndRole> userAndRoleList){
		
		return operateInsertSql(sqlId,userAndRoleList);
	}
	
	public int uncorrelateRoles(String sqlId,UserAndRole userAndRole){
		
		return operateDeleteSql(sqlId,userAndRole);
	}
	
	public User findOne(String sqlId,String id){
		
		return (User)operateSelectOneSql(sqlId,id);
	}
	
	public User findUserByUsername(String sqlId,String username){
		
		return (User)operateSelectOneSql(sqlId,username);
	}
	
	@SuppressWarnings("unchecked")
	public Set<String> findRoles(String sqlId,String username){
		roleSet.clear();
		operateSelectSql(sqlId,username).forEach(e -> roleSet.add(String.valueOf(e)));
		return roleSet;
	}
	
	@SuppressWarnings("unchecked")
	public Set<String> findPermissions(String sqlId,String username){
		permissionSet.clear();		
		((List<Object>)operateSelectSql(sqlId,username)).forEach(e -> permissionSet.add(String.valueOf(e)));
		return permissionSet;
	}
	
	public int deleteUserTable(String sqlId){
		
		return deleteForFullTable(sqlId);
	}
}
